/**
 * Copyright (C), 2015-2021, 广州同心日信息科技责任有限公司
 * FileName: ArrivalTimeDialog
 * Author: Administrator
 * Date: 2021/4/9 23:25
 * Description: 到达时间选择底部弹窗
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package com.cmw.auntapp.component;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.cmw.auntapp.R;
import com.cmw.auntapp.listener.ConfirmListener;
import com.google.android.material.bottomsheet.BottomSheetDialog;

import java.util.List;
import java.util.ArrayList;

import butterknife.BindView;
import butterknife.BindViews;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: ArrivalTimeDialog
 * @Description: java
 * @Author: Administrator
 * @Date: 2021/4/9 23:25
 * @Phone: 13922111489
 * @Email: 340360491@qq.com
 */
public class ArrivalTimeDialog extends BottomSheetDialog {
    private static final String TAG = "ArrivalTimeDialog";

    @BindView(R.id.btn_dialog_cancel)
    TextView btnCanel;

    @BindView(R.id.btn_dialog_confirm)
    TextView btnConfirm;

    private Button prevChooseBtn;

    private ConfirmListener confirmListener;

    private int value;


    public ArrivalTimeDialog(@NonNull Context context) {
        this(context, null);
    }

    public ArrivalTimeDialog(@NonNull Context context, ConfirmListener confirmListener) {
        super(context);
        this.setContentView(R.layout.dialog_time_choose);
        ButterKnife.bind(this);
        this.confirmListener = confirmListener;
    }

    /**
     * 确定事件
     * @param confirmListener
     */
    public void setConfirmListener(ConfirmListener confirmListener) {
        this.confirmListener = confirmListener;
    }

    /**
     * 取消隐藏弹窗
     */
    @OnClick(R.id.btn_dialog_cancel)
    public void doCancel() {
        this.dismiss();
    }

    /**
     * 确定
     */
    @OnClick(R.id.btn_dialog_confirm)
    public void doConfirm(View view) {
        Log.w(TAG,"当前选择的时间："+this.value);
        boolean flag = true;
        if (confirmListener != null) {
            confirmListener.execute(view);
        }
        if (!flag) {
            return;
        }
        this.dismiss();

    }

    /**
     * 获取选择的时间
     * @return  返回选择的时间
     */
    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    /**
     * 点选时间按钮
     * @param view
     */
    @OnClick({
            R.id.btn_time_5, R.id.btn_time_10, R.id.btn_time_15, R.id.btn_time_20,
            R.id.btn_time_25, R.id.btn_time_30, R.id.btn_time_35, R.id.btn_time_40,
            R.id.btn_time_45, R.id.btn_time_50, R.id.btn_time_55, R.id.btn_time_60,
    })
    public void chooseTime(View view) {
        Button currBtn = (Button)view;
        if (prevChooseBtn != null) {
            if(prevChooseBtn == currBtn) {
                return;
            }
            prevChooseBtn.setBackgroundResource(R.drawable.btn_choose_time);
        }
        currBtn.setBackgroundResource(R.drawable.btn_choose_time_active);
        Object tag = currBtn.getTag();
        this.value = Integer.parseInt(tag.toString());
        Log.w(TAG,"当前点击的按钮："+this.value+", 时间："+currBtn.getText());
        prevChooseBtn = currBtn;
    }
}